<template>
  <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
    <ul>
      <li v-for="(comment, index) in hotComments" :key="index">
        <div class="headPortrait">
          <img :src="comment.user.avatarUrl" />
        </div>

        <div>
          <h4>{{ comment.nickname }}</h4>
          <p>{{ comment.content }}</p>
        </div>
      </li>
    </ul>
  </el-col>
</template>

<script>
import api from "../../api";
import { mapState } from "vuex";

export default {
  name: "Comment",
  data() {
    return {
      hotComments: [],
    };
  },

  computed: {
    ...mapState({
      songId: (state) => state.user.clickSongId,
    }),
  },

  watch: {
    songId: {
      immediate: true,
      handler(newId) {
        const songComment = api.reqGetComment(newId);
        songComment.then((songComment) => {
          this.hotComments = songComment;
        });
      },
    },
  },
};
</script>

<style scoped lang="less">
.el-col {
  height: 600px;
  overflow-y: auto;
  margin-top: 25px;

  ul li {
    display: flex;
    margin-bottom: 25px;

    .headPortrait {
      margin-right: 10px;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;

      img {
        width: 40px;
        height: 40px;
      }
    }

    p {
      width: 200px;
    }
  }
}
</style>